// ----------------------------------
// RSDK Project: Sonic Essence
// Script Description: Time Attack Start
// Script Author: Tails LP
// ----------------------------------

//-------Aliases-------//

private alias object.value0 : object.timer
private alias object.value1 : countdown.timer

//-------Function declarations-------//

//-------Static Values-------//

//-------Tables-------//


//-------Functions-------//

reserve function TASTART_DebugDraw
reserve function TASTART_DebugSpawn

function TAStart_DebugDraw
	DrawSprite(0)
end function


function TASTART_DebugSpawn
	CreateTempObject(TypeName[TA Start], 0, object.xpos, object.ypos)
	object[tempObjectPos].drawOrder = 4
end function

event ObjectMain
	if options.gamemode == 1
		if object[currentPlayer].xpos > object.xpos
			stage.timeEnabled = true
			object[currentPlayer].controlMode = 0
			if object.alpha >= 0
				object.alpha -= 20
			else
				object.alpha = 0
			end if
		else	
			if TA.quickstart == 0
				object.alpha = 255
				if stage.timeEnabled != true
					countdown.timer++
				else
					countdown.timer = 0
				end if

			if countdown.timer == 360
				PlaySfx(SfxName[Sonic TA Start], 0)
			end if
		
				if countdown.timer <= 250
					object.value2 = 2
				end if
				if countdown.timer >= 250
					object.value2 = 14
				end if
				if countdown.timer >= 310
					object.value2 = 15
				end if
				if countdown.timer >= 360
					object.value2 = 16
				end if
				if countdown.timer >= 420
					object.value2 = 17
				end if
			else	
				object.alpha = 255
				if stage.timeEnabled != true
					countdown.timer++
				else
					countdown.timer = 300
				end if

				if countdown.timer == 55
					PlaySfx(SfxName[Sonic TA Start], 0)
				end if
		
				if countdown.timer >= 0
					object.value2 = 14
				end if
				if countdown.timer >= 30
					object.value2 = 15
				end if
				if countdown.timer >= 60
					object.value2 = 16
				end if
				if countdown.timer >= 110
					object.value2 = 17
				end if
			end if
		end if
	else
		object.type = 0
	end if
end event

event ObjectDraw
	object.inkEffect = INK_ALPHA
	object.direction = FLIP_X
	if TA.quickstart == 0
		if object.timer > 500
			object.frame += 1
			object.timer = 494
			if object.frame == 12
				object.frame = 10
			end if
		else
			object.timer ++
		endif
		temp2 = object.frame
		temp2 += 2
	else
		if object.timer > 5
			object.frame += 1
			object.timer = 0
			if object.frame == 12
				object.frame = 10
			end if
		else
			object.timer ++
		endif
		temp2 = object.frame
		temp2 += 2
	end if


	temp0 = object.xpos
	
	if object.drawOrder == 5
		DrawSpriteXY(0, temp0, object.ypos)
		object.drawOrder = 3
	else
		temp0 += 0x70000
		DrawSpriteXY(1, temp0, object.ypos)

		temp0 = object.xpos
		temp0 -= 0x300000
		temp1 = object.ypos
		temp1 += 0x100000
		DrawSpriteFX(temp2, FX_FLIP, temp0, temp1)

		AddDrawListEntityRef(5, object.entityPos)
		object.drawOrder = 5

	end if

	temp0 = object.xpos
	temp0 += 0x100000
	temp1 = object.ypos
	temp1 -= 0x200000
	DrawSpriteFX(object.value2, FX_INK, temp0, temp1)
end event

event ObjectStartup
    	LoadSpriteSheet("Global/Items.gif")
	SpriteFrame(-4, -24, 8, 48, 401, 2)	
	SpriteFrame(-3, -24, 6, 48, 410, 2)	

	SpriteFrame(-8, 0, 0, 0, 281, 2)	
	SpriteFrame(-8, 0, 24, 8, 281, 2)	
	SpriteFrame(-8, 0, 24, 8, 306, 2)	
	SpriteFrame(-16, 0, 40, 8, 331, 2)
	SpriteFrame(-24, -8, 56, 16, 281, 11)
	SpriteFrame(-24, -8, 56 ,16, 326, 28)
	SpriteFrame(-24, -8, 56 ,16, 326, 45)
	SpriteFrame(-24, -8, 56 ,16, 383, 51)
	SpriteFrame(-7, -16, 24 ,24, 394, 68)
	SpriteFrame(-7, -16, 24 ,24, 419, 68)
	SpriteFrame(-8, -7, 17, 15, 383, 2)
	SpriteFrame(-8, -9, 17, 17, 383, 18)

	SpriteFrame(0,0, 22, 16, 199, 198)	//14
	SpriteFrame(0,0, 22, 16, 222, 198)	//15
	SpriteFrame(0,0, 22, 16, 245, 198)	//16
	SpriteFrame(0,0, 50, 16, 268, 198)	//17

	SetTableValue(TypeName[TA Start], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(TAStart_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(TAStart_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 223, 172)
end event